package com.tedu.ds.dsService.service.impl;

import com.tedu.ds.dsService.mapper.DsServiceMapper;
import com.tedu.ds.dsService.pojo.dto.DsServiceParam;
import com.tedu.ds.dsService.pojo.dto.DsServiceQuery;
import com.tedu.ds.dsService.pojo.entity.DsService;
import com.tedu.ds.dsService.pojo.vo.DsServiceVO;
import com.tedu.ds.dsService.service.DsServiceService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DsServiceServiceImpl implements DsServiceService {
    @Autowired
    private DsServiceMapper dsServiceMapper;
    @Override
    public List<DsServiceVO> select(DsServiceQuery dsServiceQuery) {
        return dsServiceMapper.select(dsServiceQuery);
    }

    @Override
    public void save(DsServiceParam dsServiceParam) {
        DsService dsService=new DsService();
        BeanUtils.copyProperties(dsServiceParam,dsService);
        if(dsService.getId()==null){
            dsServiceMapper.insert(dsService);
        }else {
            dsServiceMapper.update(dsService);
        }
    }

    @Override
    public void delete(Integer id) {
        dsServiceMapper.delete(id);
    }

    @Override
    public void updateStatus(Integer userId, Integer status) {
        DsService dsService=new DsService();
        dsService.setId(userId);
        dsService.setStatus(status);
        dsServiceMapper.update(dsService);
    }

    @Override
    public List<DsServiceVO> selectByParentId(DsServiceQuery dsServiceQuery) {
        return dsServiceMapper.selectByParentId(dsServiceQuery);
    }
}
